/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ru.staf.NetworkReportGenerator;

import ru.staf.NetworkReportGenerator.V2.ConfigParser;
import ru.staf.NetworkReportGenerator.V2.Switch;
import ru.staf.NetworkReportGenerator.V2.ExcelTableOutput;
import ru.staf.NetworkReportGenerator.V2.NmapOutputParser;
import ru.staf.NetworkReportGenerator.V2.HtmlUtil;
import ru.staf.NetworkReportGenerator.V2.Panasonic.Camera;
import ru.staf.NetworkReportGenerator.V2.NetworkSnmpWorker;

/**
 *
 * @author aezhov
 */

import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Iterator;
import java.util.Set;

import org.snmp4j.smi.VariableBinding;
import org.snmp4j.smi.Variable;
import org.snmp4j.smi.OctetString;
import org.snmp4j.smi.OID;

public class Start {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        //GregorianCalendar cal1 = new GregorianCalendar(2011, 6, 28, 10, 22);
        //GregorianCalendar cal2 = new GregorianCalendar(2011, 6, 28, 11, 00);

        try {
            String configFile = System.getProperty("config.file");
            String fromDateStr = System.getProperty("from.date");
            String tillDateStr = System.getProperty("till.date");

            String[] parts1 = fromDateStr.split(":");
            String[] parts2 = tillDateStr.split(":");

            GregorianCalendar fromDate =
                    new GregorianCalendar(new Integer(parts1[2]).intValue(),
                        new Integer(parts1[1]).intValue() - 1,
                        new Integer(parts1[0]).intValue(),
                        new Integer(parts1[3]).intValue(),
                        new Integer(parts1[4]).intValue());

            GregorianCalendar tillDate =
                    new GregorianCalendar(new Integer(parts2[2]).intValue(),
                        new Integer(parts2[1]).intValue() - 1,
                        new Integer(parts2[0]).intValue(),
                        new Integer(parts2[3]).intValue(),
                        new Integer(parts2[4]).intValue());

            SysUtil.usedMemory("before ConfigParser");
          ConfigParser config = new ConfigParser(configFile, fromDate.getTime(),
                    tillDate.getTime());
            SysUtil.usedMemory("after ConfigParser");
            Set<Switch> switches = config.getSwitchList();
            SysUtil.usedMemory("after getSwitchList");
            ExcelTableOutput output =
                    new ExcelTableOutput(config.getOutputFilename());
            SysUtil.usedMemory("after ExcelTableOutput");
            output.addAll(switches);
            output.produce();
            SysUtil.usedMemory("after ExcelTableOutput.produce");
        } catch (Exception exc) {
            System.out.println("Start. ERROR during program runtime " + exc);
            exc.printStackTrace();
        }

        Runtime runtime = Runtime.getRuntime();
        long freeMem = runtime.freeMemory();
        long maxMem = runtime.totalMemory();
        long totalMem = runtime.totalMemory();

        System.out.println("====== MEMORY REPORT ======");
        System.out.println("  FreeMem: " + freeMem);
        System.out.println("  MaxMem: " + maxMem);
        System.out.println("  TotalMem: " + totalMem); 
    }
}
